package com.keshe.cart.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;


import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.keshe.common.utils.PageUtils;
import com.keshe.common.utils.Query;

import com.keshe.cart.dao.CouponDao;
import com.keshe.cart.entity.CouponEntity;
import com.keshe.cart.service.CouponService;


@Service("couponService")
public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> implements CouponService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CouponEntity> page = this.page(
                new Query<CouponEntity>().getPage(params),
                new QueryWrapper<CouponEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params, int cid){
        String commodityId = (String) params.get("cid");
        QueryWrapper<CouponEntity> wrapper = new QueryWrapper<CouponEntity>();
        if (!StringUtils.isEmpty(commodityId)) {
            wrapper.and((obj)->{
                obj.eq("cid", commodityId);
            });
        }
        if (cid == 0) {
            IPage<CouponEntity> page = this.page(new Query<CouponEntity>().getPage(params), wrapper);
            return new PageUtils(page);
        }else{
            wrapper.eq("cid", cid);
            IPage<CouponEntity> page = this.page(new Query<CouponEntity>().getPage(params), wrapper);
            return new PageUtils(page);
        }
    }

}
